package db10;

public class TicketSeller {
    private  int ticketCount = 100;

    public synchronized void sellTicket(String window){

        if (ticketCount > 0){
            System.out.println(window+ "卖出了一张票，剩余票数：" + --ticketCount);
        }else {
            System.out.println(window + "没有票了");
        }
    }

    public static void main(String[] args) {
        TicketSeller seller = new TicketSeller();

        Thread threadA = new Thread(() ->{
            for (int i = 0; i < 50; i++) {
                seller.sellTicket("A窗口");
            }
        });

        Thread threadB = new Thread(() ->{
            for (int i = 0; i < 50; i++) {
                seller.sellTicket("B窗口");
            }
        });

        threadA.start();

        threadB.start();

    }
}
